/**
 * 弃用
 */
import { setStore, getStore, clearStore } from "@/utils/storage"
import Vue from 'vue'
import { ACCESS_TOKEN } from "@/store/mutation-types"

export const TokenKey = 'Access-Token'

export function getToken() {
  return getStore(TokenKey)
}

export function setToken(token) {
  // key, token, timeout = 86400s
  return setStore(TokenKey, token, 86400)
}

export function removeToken() {
  return clearStore(TokenKey)
}

export function setFileRequestToken( url ) {
  if ( !url ) return null;
  if ( url.indexOf( 'static.dingtalk.com' ) > -1 ) return url;
  const hasParams = url.indexOf('?') > -1;
  const hostName = window._CONFIG['domianURL'];
  let path = url.split('/bonc')[1];
  
  return hostName + path + (hasParams ? '&' : '?') + 'token=' + Vue.ls.get(ACCESS_TOKEN);
}